Refactored changes to not require global state for testing