Fixed bugs, removed unused code.