Restructuring of some code