morning coffee and some cleanup/bugfix

we wrap now because edge detection would randomly not work
added a keypress buffer so we don't get two presses between iterations
moved more stuff out to their own functions for increased modularity i guess