changed wait to waitpid for background process