Fix asynchronous query logic and update to new style