after code review, some refactoring