better log and error handling