Fixed broken window size detection on startup.
Made handling of window dimensions more robust.