Fix a few typos and bugs in code