Reworked open function