Check state before opening/closing