Fixed some strange loading and saving problems and fixed painting of window