further refactoring and code simplification