improved logging and error handling