Added query alter hook
Merged
Added templates and database calls