Separated spaghetti code in proper classes and functions