Performance improvements when using js based map/reduce functions

Moved map/reduce functions and required js expressions to constructors so they're only executed once.