Minor C++ changes and sql function to fix xount