refactoring and added documentation