restructure for more flexible scopes

Change-Id: Ic10fd6bc5860c512b5b4afce9e2857523e913e53