rebuild sa code to deal with a number of issues