completed cachematic.R functions