updated for speed up and preparing for cache