added tests and fixed caching issue