Cosmetic fixes
Bug fix: Incorrect log entry when SQL query contains a question mark
Optimize code and add FRAGMENT hive variable