Refactored Bouncing ball code