improved top resize algorithm