make sure we always go back to the right buffer, and if there is no buffer to go back to, close the window