Improved movement function