Caching added. Threading implemented, but needs testing.