Implement error handling, and use log instead of fmt