fix window stacking and misc. refactor