Fix CQL statements scope; Simplify code with functions