refactored 1a and 1b to use functional patterns