updated waithandle code for unix