refactored a function to make more sense