Fixed some bugs and cleaned some code. Make the testSuite green again.