better path detection