Restructure code for an easier read