Re-structure the code