diff --git a/src/Wt/Auth/AuthModel.C b/src/Wt/Auth/AuthModel.C
index f1003442f..e7fd4d002 100644
--- a/src/Wt/Auth/AuthModel.C
+++ b/src/Wt/Auth/AuthModel.C
@@ -185,6 +185,11 @@ void AuthModel::setRememberMeCookie(const User& user)
 bool AuthModel::login(Login& login)
 {
   if (valid()) {
+    // self: keep model alive until function returns
+    // loginUser can cause Login::changed() signal
+    // to be emitted. A slot may be connected that
+    // deletes the widget that is the sole owner of this model
+    auto self = shared_from_this();
     User user = users().findWithIdentity(Identity::LoginName,
 					 valueText(LoginNameField));
     cpp17::any v = value(RememberMeField);
diff --git a/src/Wt/Auth/AuthModel.h b/src/Wt/Auth/AuthModel.h
index a3d347114..6294927d0 100644
--- a/src/Wt/Auth/AuthModel.h
+++ b/src/Wt/Auth/AuthModel.h
@@ -12,6 +12,8 @@
 #include <Wt/Auth/Identity.h>
 #include <Wt/Auth/User.h>
 
+#include <memory>
+
 namespace Wt {
   namespace Auth {
 
@@ -52,7 +54,7 @@ class OAuthService;
  *
  * \ingroup auth
  */
-class WT_API AuthModel : public FormBaseModel
+class WT_API AuthModel : public FormBaseModel, public std::enable_shared_from_this<AuthModel>
 {
 public:
   //! \brief Password field
diff --git a/src/Wt/Auth/AuthWidget.C b/src/Wt/Auth/AuthWidget.C
index 2951d002d..3857d3530 100644
--- a/src/Wt/Auth/AuthWidget.C
+++ b/src/Wt/Auth/AuthWidget.C
@@ -46,7 +46,7 @@ LOGGER("Auth.AuthWidget");
 AuthWidget::AuthWidget(const AuthService& baseAuth,
 		       AbstractUserDatabase& users, Login& login)
   : WTemplateFormView(WString::Empty),
-    model_(new AuthModel(baseAuth, users)),
+    model_(std::make_shared<AuthModel>(baseAuth, users)),
     login_(login)
 {
   init();
@@ -77,9 +77,9 @@ void AuthWidget::init()
   app->theme()->apply(this, this, AuthWidgets);
 }
 
-void AuthWidget::setModel(std::unique_ptr<AuthModel> model)
+void AuthWidget::setModel(const std::shared_ptr<AuthModel> &model)
 {
-  model_ = std::move(model);
+  model_ = model;
 }
 
 void AuthWidget::setRegistrationEnabled(bool enabled)
@@ -171,11 +171,6 @@ void AuthWidget::closeDialog()
   }
 }
 
-std::unique_ptr<RegistrationModel> AuthWidget::registrationModel()
-{
-  return createRegistrationModel();
-}
-
 std::unique_ptr<RegistrationModel> AuthWidget::createRegistrationModel()
 {
   auto result = std::unique_ptr<RegistrationModel>
@@ -190,7 +185,7 @@ std::unique_ptr<RegistrationModel> AuthWidget::createRegistrationModel()
 
 std::unique_ptr<WWidget> AuthWidget::createRegistrationView(const Identity& id)
 {
-  auto model = registrationModel();
+  auto model = createRegistrationModel();
 
   if (id.isValid())
     model->registerIdentified(id);
@@ -231,7 +226,7 @@ std::unique_ptr<WWidget> AuthWidget
 {
   return std::unique_ptr<WWidget>
     (new UpdatePasswordWidget
-     (user, registrationModel(),
+     (user, createRegistrationModel(),
       promptPassword ? model_ : std::shared_ptr<AuthModel>()));
 }
 
diff --git a/src/Wt/Auth/AuthWidget.h b/src/Wt/Auth/AuthWidget.h
index c3bd993f9..f0f02a2c0 100644
--- a/src/Wt/Auth/AuthWidget.h
+++ b/src/Wt/Auth/AuthWidget.h
@@ -95,7 +95,7 @@ public:
    *
    * This sets a model to be used for authentication.
    */
-  void setModel(std::unique_ptr<AuthModel> model);
+  void setModel(const std::shared_ptr<AuthModel> &model);
 
   /*! \brief Returns the model.
    *
@@ -374,8 +374,6 @@ private:
   void oAuthStateChange(OAuthProcess *process);
   void oAuthDone(OAuthProcess *process, const Identity& identity);
   void updatePasswordLoginView();
-
-  std::unique_ptr<RegistrationModel> registrationModel();
 };
 
   }
diff --git a/src/Wt/WContainerWidget.C b/src/Wt/WContainerWidget.C
index 5eb008ca8..bf132a9aa 100644
--- a/src/Wt/WContainerWidget.C
+++ b/src/Wt/WContainerWidget.C
@@ -67,7 +67,7 @@ void WContainerWidget::setLayout(std::unique_ptr<WLayout> layout)
   // we need to delete the old value first, otherwise we run into problems
   // FIXME: maybe the code should be fixed so this is not necessary? Having
   //        to call reset() first feels dirty
-  layout_.reset();
+  clear();
 
   layout_ = std::move(layout);
   if (layout_)
