Refactored obstacle avoidance logic into its own file