refactor initialization for mean field, fix many bugs