Fixed non-zero exit code returned to Erlang VM

According to http://linux.die.net/man/2/waitpid, WEXITSTATUS() is the correct way to get exit code from a value received from waitpid() function. 

I'm not sure if this is the best place to run WEXITSTATUS(), but I don't understand the code well enough to find a better place :)