1. Convert more functions to use forEach() and foldl() instead of explicit loops.
2. Get rid of some warnings from the test file.