Implemented proper collision detection.