Updated to use caching and removed some debug messages