optimized path tracking and neighbor handling
cleaned up the code