Preventing infinite resize() loop