imported changes from sapi