Fixed Error checking