Fixed some bugs associated with collision detection.