refined and optimised input/movement code