now working incl tests