Fixed detach method with support for menu hierarchies.