Re-factored repeated code in XP system