Fixed compilation error
Added rudimentary caching. Will need to refine this more.