fix bug when no invalid move.
optimize code organization.