Rewrote first four functions with lambda and reduce/filter/map.