completed anf transformation function