Refactor computePath