Fixed wrong counting of squares