Fixed weird ball jumps; refactored code