add collision detection algorithm