added some tests, refactored error handling, and made progress on the TODOs