Fix attach / detach issues in model