Refactoring our humongous code

Here's some refactoring I did on our humongous code. check it out.