fixes for variable warnings and notices #1732714, #1732712, #1732710, #1732702 and possible more, but this needs testing