Restructuring some code. No functionality changes