refactored variables and cache