Added caching, some speed ups