diff --git a/generator/Makefile b/generator/Makefile
index 1b1199e3dbda2c0cc333f7974d07eb1cd6ca35ff..bf11852d110c122d3d02c909fbb0e87490d78d64 100644
--- a/generator/Makefile
+++ b/generator/Makefile
@@ -7,13 +7,7 @@
 #
 # requires: opam switch 4.02.1; eval `opam config env`
 
-
-###############################################################
-# Global options
-
-.PHONY: all clean
-
-all:
+# TODO: test/lambda is not longer supported
 
 ###############################################################
 # Paths
@@ -26,6 +20,14 @@ TESTS_ML    := $(wildcard $(TESTS_DIR)/*.ml)
 JSREF_ML    := $(wildcard $(TESTS_DIR)/$(JSREF_DIR)/*.ml) 
 JSREF_MLI   := $(wildcard $(TESTS_DIR)/$(JSREF_DIR)/*.mli)
 
+###############################################################
+# Global options
+
+.PHONY: all full log unlog clean .log.js .unlog.js  .token.js
+
+# Do not delete intermediate files.
+.SECONDARY:
+
 
 ###############################################################
 # Tools
@@ -39,10 +41,6 @@ GENERATOR := ./main.byte
 
 LINEOF := ./lineof.byte
 
-# Do not delete intermediate files.
-.SECONDARY:
-.PRECIOUS: *.vio
-
 
 ###############################################################
 # Dependencies
@@ -55,43 +53,21 @@ endif
 
 
 ###############################################################
-# Short targets
+# Rules
 
 all: main.byte
 
-%.byte: *.ml _tags
-	$(OCAMLBUILD) $@
-
-stdlib:
-	$(CC) stdlib_ml/stdlib.mli
-
-%.inferred.mli: _tags
-	$(OCAMLBUILD) $@
-	cp _build/$@ .
+##### Compilation of STDLIB
 
-# In case we want to rebuild any .v, but we're likely to be modifying the resulting .mls now anyway...
-.PRECIOUS: tests/%.ml
-tests/%.ml: tests/%.v
-	$(MAKE) -C $(CURDIR)/../../../lib/tlc/src
-	cd $(<D) && coqc -I $(CURDIR)/../../../lib/tlc/src $(<F)
-	cd $(@D) && rm *.mli
-	cd $(@D) && $(CURDIR)/../../ml-add-cstr-annots.pl *.ml
+$(STDLIB_DIR)/stdlib.cmi: $(STDLIB_DIR)/stdlib.mli
+	$(CC) $<
 
-.PRECIOUS: tests/jsref/*.ml tests/jsref/*.log.js  tests/jsref/*.unlog.js  tests/jsref/*.token.js
-.PHONY: .all .log.js .unlog.js  .token.js
+##### Rule for binaries
 
+%.byte: *.ml _tags
+	$(OCAMLBUILD) $@
 
-
-
-#tests/jsref/%.ml:
-#	$(MAKE) -C $(CURDIR)/../../.. interpreter
-#	cp ../../../interp/src/extract/*.ml tests/jsref/
-#	../../convert-ml-strings.pl tests/jsref/*.ml
-#	cd $(@D) && $(CURDIR)/../../ml-add-cstr-annots.pl *.ml
-
-# tests/%.cmi: tests/%.log.js
-# tests/jsref/%.cmi: tests/jsref/%.log.js
-# tests/jsref/BinNat.cmi : tests/jsref/BinNat.log.js 
+##### Rule for dependencies
 
 tests/%.mli.d: tests/%.mli
 	$(OCAMLDEP) -I $(<D) $< | $(DEPSED) > $@
@@ -99,9 +75,21 @@ tests/%.mli.d: tests/%.mli
 tests/%.ml.d: tests/%.ml
 	$(OCAMLDEP) -I $(<D) $< | $(DEPSED) > $@
 
+##### Rule for cmi
+
 tests/%.cmi: tests/%.ml main.byte stdlib 
 	./main.byte -mode cmi -I $(<D) $<
 
+##### Custome cmi rules for compilation of mli files without ml source
+
+$(JSREF_PATH)/Translate_syntax.cmi: $(JSREF_PATH)/Translate_syntax.mli $(JSREF_PATH)/JsSyntax.cmi stdlib
+	ocamlc -I $(JSREF_PATH) -I stdlib_ml -open Stdlib $<
+
+$(JSREF_PATH)/Prheap.cmi: $(JSREF_PATH)/Prheap.mli stdlib $(JSREF_PATH)/JsSyntax.cmi
+	ocamlc -I $(JSREF_PATH) -I stdlib_ml -open Stdlib $<
+
+##### Rule for log/unlog/token
+
 tests/%.log.js: tests/%.ml main.byte stdlib tests/%.cmi
 	./main.byte -mode log -I $(<D) $<
 
@@ -111,54 +99,27 @@ tests/%.unlog.js: tests/%.ml main.byte stdlib tests/%.cmi
 tests/%.token.js: tests/%.ml main.byte stdlib tests/%.cmi  
 	./main.byte -mode token -I $(<D) $<
 
-tests/%.all: tests/%.log.js tests/%.unlog.js tests/%.token.js
-	touch $@
-
-#tests/%.cmi: tests/%.ml main.byte stdlib
-#	./main.byte -mode unlog -I $(<D) $<
-
-
-# ad hoc rules
-
-tests/jsref/Translate_syntax.cmi: tests/jsref/Translate_syntax.mli tests/jsref/JsSyntax.cmi stdlib
-	ocamlc -I tests/jsref -I stdlib_ml -open Stdlib $<
-
-tests/jsref/Prheap.cmi: tests/jsref/Prheap.mli stdlib tests/jsref/JsSyntax.cmi
-	ocamlc -I tests/jsref -I stdlib_ml -open Stdlib $<
+##### Rule for lineof.js
 
+$(JSREF_PATH)/lineof.js: lineof.byte $(JSREF_ML:.ml=.token.js)
+	./lineof.byte -o $@ $(JSREF_ML:.ml=.token.js)
 
 
 
-# tests/%.cmi: tests/%.mli stdlib
-#	ocamlc -I stdlib_ml -open Stdlib -I $(<D) $<
-
-
-tests: $(TESTS_ML:.ml=.log.js) $(TESTS_ML:.ml=.token.js)
-
-tests/lambda: tests/lambda/Lambda.log.js
-
-tests/jsref: tests/jsref/JsInterpreter.log.js
-tests/jsrefunlog: tests/jsref/JsInterpreter.unlog.js
-
-
-
-
-
-######### lineof target #########
-
-tests/jsref/lineof.js: lineof.byte $(ML_JSREF:.ml=.token.js)
-	./lineof.byte -o $@ $(ML_JSREF:.ml=.token.js)
-
-
 #####################################################################
 # Short targets
 
-unlog: $(JSREF_ML:.ml=.unlog.js) 
+main: main.byte
+
 full: $(JSREF_ML:.ml=.log.js) $(JSREF_ML:.ml=.unlog.js) $(JSREF_ML:.ml=.token.js)
-lineof: tests/jsref/lineof.js
 
+unlog: $(JSREF_ML:.ml=.unlog.js) 
+
+lineof: $(JSREF_PATH)/lineof.js
 
+stdlib: $(STDLIB_DIR)/stdlib.cmi
 
+tests: $(TESTS_ML:.ml=.log.js) $(TESTS_ML:.ml=.token.js)
 
 
 #####################################################################
@@ -166,6 +127,9 @@ lineof: tests/jsref/lineof.js
 
 DIRTY_EXTS := cmi,token.js,log.js,unlog.js,d,ml.d,mli.d
 
+clean_lineof:
+	rm -f $(JSREF_PATH)/lineof.js
+
 clean_tests:
 	bash -c "rm -f $(TESTS_DIR)/*.{$(DIRTY_EXTS)}"
 	bash -c "rm -f $(TESTS_DIR)/$(JSREF_DIR)/*.{$(DIRTY_EXTS)}"
@@ -173,14 +137,10 @@ clean_tests:
 clean_stdlib:
 	rm -f $(STDLIB_DIR)/*.cmi
 
-clean: clean_tests clean_stdlib
+clean: clean_lineof clean_tests clean_stdlib
 	rm -rf _build
 	rm -f *.native *.byte
 
-clean_cmi: clean_tests clean_stdlib
-cleanall: clean clean_cmi
-
-
 
 
 #####################################################################
@@ -191,10 +151,23 @@ debug: main.d.byte
 native: _tags
 	$(OCAMLBUILD) main.native
 
+##### Shorthand
+
+tests/%.all: tests/%.log.js tests/%.unlog.js tests/%.token.js
+	touch $@
 
 #####################################################################
 # Deprecated
 
+####
+#
+#%.inferred.mli: _tags
+#	$(OCAMLBUILD) $@
+#	cp _build/$@ .
+
+# tests/lambda: tests/lambda/Lambda.log.js
+
+
 #ifeq ($(findstring clean,$(MAKECMDGOALS)),)
 #-include $(JSREF_ML:.ml=.ml.d)
 #-include $(JSREF_MLI:.mli=.mli.d)
@@ -209,4 +182,30 @@ native: _tags
 # 	bash -c "rm -f $(TESTS_DIR)/lambda/*.{$(DIRTY_EXTS)}"
 
 # clean_jsref:
-#	rm -f tests/jsref/*.ml.d tests/jsref/*.mli.d tests/jsref/*.log.js tests/jsref/*.unlog.js tests/jsref/*.token.js  tests/jsref/*.cmi
+#	rm -f $(JSREF_PATH)/*.ml.d $(JSREF_PATH)/*.mli.d $(JSREF_PATH)/*.log.js $(JSREF_PATH)/*.unlog.js $(JSREF_PATH)/*.token.js  $(JSREF_PATH)/*.cmi
+
+# PRECIOUS probably not useful:
+# .PRECIOUS: $(JSREF_PATH)/*.ml $(JSREF_PATH)/*.log.js $(JSREF_PATH)/*.unlog.js  $(JSREF_PATH)/*.token.js
+# .PRECIOUS: *.vio
+#.PRECIOUS: tests/%.ml
+
+
+
+#tests/%.ml: tests/%.v
+#	$(MAKE) -C $(CURDIR)/../../../lib/tlc/src
+#	cd $(<D) && coqc -I $(CURDIR)/../../../lib/tlc/src $(<F)
+#	cd $(@D) && rm *.mli
+#	cd $(@D) && $(CURDIR)/../../ml-add-cstr-annots.pl *.ml
+
+
+
+
+#$(JSREF_PATH)/%.ml:
+#	$(MAKE) -C $(CURDIR)/../../.. interpreter
+#	cp ../../../interp/src/extract/*.ml $(JSREF_PATH)/
+#	../../convert-ml-strings.pl $(JSREF_PATH)/*.ml
+#	cd $(@D) && $(CURDIR)/../../ml-add-cstr-annots.pl *.ml
+
+# tests/%.cmi: tests/%.log.js
+# $(JSREF_PATH)/%.cmi: $(JSREF_PATH)/%.log.js
+# $(JSREF_PATH)/BinNat.cmi : $(JSREF_PATH)/BinNat.log.js