fixed some bugs in SAM format generation function