Why saving output and returning it is a problem? There's no performance issue. Also by doing so, you can use a local variable to save old layout,  which is cleaner than declaring a private var.