#877 - Make toWriteCommand tail recursive.