improve message handling in demo and template