Added closing function when closing mainpage