changed wait to waitpid for fg commands