improved collision detection. added tests