Clean up

Added some more documentation, and some more error checks.