Fixed some bugs and added some more error messages