refacroting Query to Statement