some code refactoring: