Code cleanup to remove repeated code.