Implemented collision detection and resolving.