reorganized event handler code and started on resize functionality.