Switched around attach and detach logic

This will help with integrity constraints, but will not be a final solution.

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