added square sorting code