Refactor, no functional change, make it easier to write test
Proper Fix for #992