fixed some problems writing to file in SA