diff --git a/semantics/management/commands/connect_frames_to_entries.py b/semantics/management/commands/connect_frames_to_entries.py
new file mode 100644
index 0000000..b1dfe2c
--- /dev/null
+++ b/semantics/management/commands/connect_frames_to_entries.py
@@ -0,0 +1,26 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+
+import sys, os, codecs
+
+from django.core.management.base import BaseCommand
+
+from dictionary.models import Entry
+from semantics.models import SemanticFrame
+from settings import PROJECT_PATH
+
+class Command(BaseCommand):
+    args = 'none'
+    help = ''
+
+    def handle(self, **options):
+        connect_frames()
+
+def connect_frames():
+    entries = Entry.objects.all()
+    for entry in entries:
+        frames = entry.actual_frames()
+        for frame in frames:
+            frame.entry = entry
+            frame.save()
+                                
diff --git a/semantics/models.py b/semantics/models.py
index 378eb1f..10de902 100644
--- a/semantics/models.py
+++ b/semantics/models.py
@@ -2,7 +2,7 @@
 
 from django.db import models
 
-from dictionary.models import Argument, Frame, Position, NKJP_Example
+from dictionary.models import Argument, Frame, Position, NKJP_Example, Entry
 from wordnet.models import LexicalUnit, Synset
 from django.contrib.auth.models import User
 from datetime import datetime
@@ -43,6 +43,8 @@ class SemanticFrame(models.Model):
     removed = models.BooleanField(default=False)
     author = models.ForeignKey(User, null=True)
     opinion = models.ForeignKey(FrameOpinion, null=True)
+        # hasło w Walentym
+    entry = models.ForeignKey(Entry, null=True, related_name='semantic_frames')
     
     def role_exists(self, role_name):
         if self.complements.filter(roles__role=role_name).exists():
diff --git a/semantics/saving.py b/semantics/saving.py
index 27d981b..e89c15b 100644
--- a/semantics/saving.py
+++ b/semantics/saving.py
@@ -20,7 +20,7 @@ def make_operations(lemma_id, operations):
     for operation in operations:
         if operation['operation'] == "create_frame":
             luids = [int(m['id']) for m in operation['meanings']]
-            translation['frame_id'][int(operation['id'])] = create_frame(luids)
+            translation['frame_id'][int(operation['id'])] = create_frame(entry, luids)
         elif operation['operation'] == "add_unit":
             translation['unit_id'][int(operation['unit']['id'])] = add_unit(entry, operation['unit'])
         elif operation['operation'] == "remove_frame":
@@ -134,8 +134,8 @@ def make_operations(lemma_id, operations):
         else:
             pass
         
-def create_frame(luids):
-    frame = SemanticFrame()
+def create_frame(entry, luids):
+    frame = SemanticFrame(entry=entry)
     frame.save()
     for id in luids:
         lu = LexicalUnit.objects.get(id=id)
diff --git a/semantics/static/js/semantics_lexical_units.js b/semantics/static/js/semantics_lexical_units.js
index b74a897..f3ee4d4 100644
--- a/semantics/static/js/semantics_lexical_units.js
+++ b/semantics/static/js/semantics_lexical_units.js
@@ -213,10 +213,11 @@ function getMeaningsSelectionForFrame(frame_id) {
                     options.push(schemas_content[sch].display.arguments[0][k].lex);
 		} 
 	    } 
+            var lex = {lemma: base, args: options};
 	    if (hasRefl(sch)) {
-		options.push(['się']);
+		lex.lemma = base + " się";
 	    }
-	    lexicalisation.push(options);
+	    lexicalisation.push(lex);
 	} 
     } 
 
@@ -229,25 +230,18 @@ function getMeaningsSelectionForFrame(frame_id) {
 
 function getFormForLexicalisation(lexicalisation) {
     var result = "";
-    var perms = permutations(lexicalisation);
     var i;
-    for (i = 0; i < perms.length; i++) {
-        result += lexicalisationForm(cartesian(perms[i]));
+    for (i = 0; i < lexicalisation.length; i++) {
+        var perms = permute(lexicalisation[i].args);
+        var j;
+        for (j = 0; j < perms.length; j++) {
+            result += lexicalisationForm(lexicalisation[i].lemma, cartesian(perms[j]))
+        }
+        result += '<br\>';
     }
     return result;
 }
 
-function permutations(lllist) {
-    //return lllist;
-    if (lllist.length == 0) {
-        return [];
-    } else {
-        var shortlllist = lllist.slice();
-        shortlllist.splice(0, 1);
-        return permute(lllist[0]).concat([[]].concat(permutations(shortlllist)))
-    }
-}
-
 function permute(list) {
     var i;
     if (list.length == 0) {
@@ -292,7 +286,7 @@ function cartesian(llist) {
     return result;
 }
 
-function lexicalisationForm(tokenised) {
+function lexicalisationForm(lemma, tokenised) {
     var display = "";
     var i;
     for (i = 0; i < tokenised.length; i++) {
@@ -301,12 +295,12 @@ function lexicalisationForm(tokenised) {
         } else {
 	    var j;
 	    for (j = 0; j < lexical_units.length; j++) {
-		if (base + " " + tokenised[i].join(" ") == lexical_units[j].base) {
+		if (lemma + " " + tokenised[i].join(" ") == lexical_units[j].base) {
 		    return "";
 		}
 	    }
-            display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?)
-            display += base + " " + tokenised[i].join(" ") + "<br\>";
+            display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + lemma + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?)
+            display += lemma + " " + tokenised[i].join(" ") + "<br\>";
         }
     }
     return display;