Optimized get_tagged method

Removed unneeded code.
Only use one query and no more silly array iterations.