midi stepsequencer problems

hello! i built a simple 8 step midi sequencer. i use 2 buttons for navigation and setting the note: 1 button to go to the next step, 1 button to read a potentiometer and set a note number to the actual step. so i read the buttons very often ;) during this the sequencer navigates through the steps and outputs the notes. [dunno how to describe better]

my problem is: the timing is not "tight". sometimes a note comes out slightly to early. i tried to get rid of this with 1ms delays after the output of the notes and the button read functions (so that the controller has sort of "time to calculate" ;) ). but that does not solve the problem :( and right no, i don't have any idea what to try next. so if anybody could help me...? would be nice :)