Fixed fork call and error checking