Fixed a few bugs and a typo