some logical refactoring