#91 cleaned up code, added some documentation