Fixed bugs and removed most test and unused code