added magnitude function