some minor refactoring and commenting