Added in a SmartResize function to improve handling window resize event