adding lots of "ported" code from SA app