added documentation, cleaned up code v1