Re-factor code