Need to look this "state" code over better