merged master with improved collision detection