fixed incorrect error check