reorganizing helper functions to improve code modularity