Collision with multiple obstacles with better code