Fixed some error handling.