Fixed error-checking