better logging and error handling