added comments, refactored a bit
Adjusted docs