Added Database class and fixed caching