initial version with cacheing
make profiling switchable