Fixed a bug in is_valid_sequence.