a little bit of refactoring and commenting