restructure + new sp function