selectState implementation and formatting fixes