refactoring to work with external calls