Made tag search in api.py more robust