using closures and functional programming concepts to minimize lines of code