finished draft of checkState function