implement caching
refactor debug code out