Major refectoring and updates