Cleaned up collision detection code.