refactor and cache