refactor some code and fix non-passing turn logic.