Fixing order of if statements for reading files