Refactored opening code out of header file