fixed sql error, minor template changes