Further tweaks to error checking and removed hardcoded path