Switched around attach and detach logic

This will help with integrity constraints. But not be a complete solution

Signed-off-by: Andreas Heiberg <git@andreas-heiberg.com>