Restructuring of code (partially done)