fixed a bug with squared sum