protected byte[] findBases(SAMSequenceRecord record, boolean tryNameVariants) {
		{ // check cache by sequence name:
			String name = record.getSequenceName();
			byte[] bases = findInCache(name);
			if (bases != null) {
				log.debug("Reference found in memory cache by name: " + name);
				return bases;
			}
		}

		String md5 = record.getAttribute(SAMSequenceRecord.MD5_TAG);
		{ // check cache by md5:
			if (md5 != null) {
				byte[] bases = findInCache(md5);
				if (bases != null) {
					log.debug("Reference found in memory cache by md5: " + md5);
					return bases;
				}
			}
		}

		byte[] bases;

		{ // try to fetch sequence by name:
			bases = findBasesByName(record.getSequenceName(), tryNameVariants);
			if (bases != null) {
				Utils.upperCase(bases);
				return bases;
			}
		}

		{ // try to fetch sequence by md5:
			if (md5 != null)
				try {
					bases = findBasesByMD5(md5);
				} catch (Exception e) {
					if (e instanceof RuntimeException)
						throw (RuntimeException) e;
					throw new RuntimeException(e);
				}
			if (bases != null) {
				return bases;
			}
		}

		{ // try @SQ:UR file location
			if (record.getAttribute(SAMSequenceRecord.URI_TAG) != null) {
				ReferenceSequenceFromSeekable s = ReferenceSequenceFromSeekable
						.fromString(record.getAttribute(SAMSequenceRecord.URI_TAG));
				bases = s.getSubsequenceAt(record.getSequenceName(), 1, record.getSequenceLength());
				Utils.upperCase(bases);
				return bases;
			}
		}
		return null;
	}