Proper error checking and logging