Implemented autoclosing window functionality