First working version of the open and close methods