modified cachematix.R