Refactored the return statement in moveWhileOnScreen