Modified caching system, fixed deallocation bugs