Further refactoring to enable external usage