main refectoring