Moved the code to find the starting directory into its own function