Fix typos and remove obsolete code, fix bugs