Removed redundant code and improved window creation.