fixes to SAPI.c