Bug fixes and improved cache