Refactored getting a file path into a function