Added caching mechanism. Still need to write a unit test and fix some
small bugs