Structured and simplified the code.