Refactor internals