fixed collision detection loop