added codes for sorting generated sequence