changed prefix handling

Now, only those prefixes are added to the query which are actually used in the query