implemented priority and cache. it shouldn't crash the computer due to mem leaks now!