collapse the two functions into one