cleaning up code and adding docs