added docs
beautified code