changed to try wait trick described on unixstackexchange