refactored square handling