Code cleanup to remove duplication