fix bugs. test complete for FM and AFM