Updated to work with latest template syntax, and patched table mode