Changed the query from cursor to one, which ...

... reduces unnecessary list processing and cursor creation.