Refactored Code. Changed all functions to map/reduce/filter with lambda statments.