improved workaround for visualstatemanager not working before template loaded.