Bug fix in checking for returned sql data