Better error handling, now logging to file