Added error checking to window creation