Refactor rules clean square and calculaG