consolidated two specified functions into one general function that is more elegant