added docs and refactored some