fixing safe_square method