Added caching and various small changes