merged two functions into one