Fixed segfault, seperated the cache, cleaned up