Put separate functions into one function as they are in original