Refactor path handling