refactoring and commenting done