Lot of code cleanup