fix bouncing off the horizontal edges of the screen

also add a docstring to every function