Removed all switch statements, refactored code, and made the open/close methods perform faster