Added some code for ball bounds checking.