completed the first part of collision detection