Finished first round of code cleanup