More error handling and other fixes