Refactored code for resolvingWallCollisions.