Updated bam.cpp