[core] remove some redundant reset im call.

reset im being called before onclose makes onclose meaningless.
remove some redundant reset and make sure onclose is called before
reset im.