added simple caching, fixed bugs