now calc_midstate() is working