Moved static functions to external file to help later security backports
Now escaping apostrophes when building queries to prevent SQL injection