Combine some duplicated code.