adding logic to better handle nested tabs