bugfixes + tests + manager::detach
(cherry picked from commit d61ed7d)