solution for maximum square - could definitely do with some pruning