error handling and bug fixes