Added window resize, and refactored into functions