Error checking improved