Fix several problems, remove unused classes, clean up some code.