diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
index b26d2a2bc0bb117b790ff7973fb01df8b71bbd42..0ae1741a6a31cc700b1868dbb8d022db6dcd09ca 100644
--- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
+++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
@@ -322,8 +322,8 @@ public class OverlayRestImpl extends BaseRestImpl {
     if (Configuration.ANONYMOUS_LOGIN.equals(user.getLogin())) {
       throw new SecurityException("You have no privileges to add overlay");
     }
-    Project project = getProjectService().getProjectByProjectId(projectId, token);
-    if (project == null) {
+    Model model = getModelService().getLastModelByProjectId(projectId, token);
+    if (model == null) {
       throw new QueryException("Project with given id doesn't exist");
     }
     ColorSchemaType colorSchemaType = ColorSchemaType.GENERIC;
@@ -367,10 +367,10 @@ public class OverlayRestImpl extends BaseRestImpl {
               .name(name).user(user)
               .colorSchemaType(colorSchemaType)
               .directory(".")
-              .project(project)
+              .project(model.getProject())
               .googleLicenseConsent(googleLicenseConsent.equalsIgnoreCase("true")));
 
-      int count = layoutService.getCustomLayouts(project, token, false, user).size();
+      int count = layoutService.getCustomLayouts(model.getProject(), token, false, user).size();
       layout.setOrderIndex(count);
       layoutService.updateLayout(layout);
 
diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java
index 5e48bc293e83552acd87b546f97a616ebbae8f20..17c5e1d6fc792ae8b25ef5594f4ed155c86926d2 100644
--- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java
+++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java
@@ -417,7 +417,7 @@ public class LayoutService implements ILayoutService {
     fileEntry.setOwner(params.getUser());
     topLayout.setInputData(fileEntry);
     topLayout.setDescription(params.getDescription());
-    params.getProject().addLayout(topLayout);
+    topLayout.setProject(params.getProject());
     topLayout.setCreator(params.getUser());
     layoutDao.add(topLayout);