Fixed various errors, removed unused code.