More error catching and better error handling