Issue #1219724 by Jose Reyero: Better handling of array and multiple variables. Moved format function to main module so it is always available.