Fixed bug in horizontal movement detection