Re-organise code for clarity