Restructuring some more code