add more logging and error handling