switched switched order of error handling to see if it makes a difference