optimize calc code for the common path of quick queries