added use of template file
using scan() to get column names
fixed factor bug in reduceGroups()