Rewrite to use gift rather than system calls.