Added function for sum of squared differences