Code cleanup and keeping flash when redirecting