more refactor of add_sma