Fixed bugs in WindowManager