refactor player logic to state machine style.