fix issue with meanfield init and speedup code