added in logging code and get next state code