functions and helpers refactored