initial refactoring for functional style