Fixing Caching (to work in threads) and some lib errors