put most of the functionality into methods, accounted for window resize