20141120 add state machine, fix collision detector