add automize part of codebook
add helper function
add helper function
huge rewrite:more reproductible,do not compute cached dt
more caching
more cleaning/restoring