implemented caching, removed some obsolete code