Fix nif to avoid segfault on upgrade