Re-factoring code