added an additional error check