Improve error handling. Closes #11.