added check for bamfile=None