updated error handling and database local