Sort depending on state