Writef with var fix, tests

Comibines Thomas' futures and a bug fix