added doc, cleaned up code