Improve window handling