auxiliary functions and code refactoring