added magsq function