added cossq function, not perfect yet