added spreading over ANF, tidied code