reimplemented the code for finding least common parallel state.