Added debug logging to methods
Added a test, fixed another
Added error handling, minor refactors.