bugfixes to SAM