Program now works with irregular window dimentions