a lot of code cleanup