added documentation; cleaned up code