added checkOpen function