another try with refactoring