Fixed some error handling and typos.