Refactered a lot of code.