Fixed a few bugs and error messages