Adding unit tests, fixing a cache problem
Merging unit tests and fixes from 3.1 to 3.2