Refactored the path code.