Fixed incorrect variable in error check