Added logic for states 0 through 2