Fix #58 Improve logging and error handling