Added error handling for fork call