Added error handling and documentation, closes #1.