added logic for ending turn