cleaned up code, added documentation