Fixed a number of bugs and spelling errors