Condense this into one function.