FlatFile bug fixes

and some template fixes...