Re-structuring code