Implemented the on_open function