refactoring internals