Fixed some error checking issues