refactoring and docs added