finished implementing the open function