Fix close button so it works indefinitely

Extensive but important fixes to make open and close button work as often as needed.