Fix NIF and Average bug