finished ghost controller logic and state machine