split some functions from do_SPAM()