Implemented the close method