Refactor inner workings of registry.js