fix several errors and simulation