Updated error handling and defined directories