Fixed part of the error checking

This could have caused problems later