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