Fixing error checking