better query implementation