cleanups and add some test cases
Add flatMap. Refactor tests for map/flatMap to use arbitrary functions instead of hard coded.