Refactored tons of code