Implemented caching

Partially fixes #136