refectoring bug fixing and more.