Lots of code cleanup!