Condense code into single function.