Structured the code using regions