error handling and other fixes