Cleaner error checking code