Clean up NIF code