added layout switching support to the handler