Re-arrange code