Better error handling, fixed typos