rewrite to nif