diff --git a/orchestrallily.ly b/orchestrallily.ly
index c40cbc7e813aa1320948bd7eda74a364a34c9678..df0c8ef55b59d06678eb4538cad3ff0e2e1e1243 100644
--- a/orchestrallily.ly
+++ b/orchestrallily.ly
@@ -264,7 +264,7 @@ orchestralScoreStructure = #(define-music-function (parser location structure) (
 % the property or an empty list, if no pre-defined variable could be found
 #(define (oly:generate_property_pair prop piece instr type)
   (let* ((val (namedPieceInstrObject piece instr type)))
-    (if (not-null? val) (list 'assign prop val) '())
+    (if (not-null? val) (list 'assign prop val) '() )
   )
 )
 % Generate the properties for the staff for piece and instr. Typically, these
@@ -313,8 +313,10 @@ orchestralScoreStructure = #(define-music-function (parser location structure) (
 % Automatic score generation
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+% \setUserBook ##t/##f sets a flat to determine whether the calls to createScore
+% are from within a book block or not
 #(define oly:score_handler collect-scores-for-book)
-useBook = #(define-music-function (parser location usebook) (boolean?) 
+setUseBook = #(define-music-function (parser location usebook) (boolean?) 
   (if usebook
     (set! oly:score_handler book-score-handler)
     (set! oly:score_handler toplevel-score-handler)
@@ -323,6 +325,66 @@ useBook = #(define-music-function (parser location usebook) (boolean?)
 )
 
 
+% Two functions to handle midi-blocks: Either don't set one, or set an empty 
+% one so that MIDI is generated
+#(define (oly:set_no_midi_block score) '())
+#(define (oly:set_midi_block score) 
+  (let* ((midiblock (if (defined? '$defaultmidi) 
+                        (ly:output-def-clone $defaultmidi) 
+                        (ly:make-output-def))))
+    (ly:output-def-set-variable! midiblock 'is-midi #t)
+    (ly:score-add-output-def! score midiblock)
+  )
+)
+
+% \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
+% be generated
+#(define oly:apply_score_midi oly:set_no_midi_block)
+setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
+  (if createmidi
+    (set! oly:apply_score_midi oly:set_midi_block)
+    (set! oly:apply_score_midi oly:set_no_midi_block)
+  )
+  (make-music 'Music 'void #t)
+)
+
+
+% Two functions to handle layout-blocks: Either don't set one, or set an empty 
+% one so that a PDF is generated
+#(define (oly:set_no_layout_block score) '())
+#(define (oly:set_layout_block score) 
+  (let* ((layoutblock (if (defined? '$defaultlayout) 
+                        (ly:output-def-clone $defaultlayout) 
+                        (ly:make-output-def))))
+    (ly:output-def-set-variable! layoutblock 'is-layout #t)
+    (ly:score-add-output-def! score layoutblock)
+  )
+)
+
+% \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
+% be generated
+#(define oly:apply_score_layout oly:set_no_layout_block)
+setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
+  (if createlayout
+    (set! oly:apply_score_layout oly:set_layout_block)
+    (set! oly:apply_score_layout oly:set_no_layout_block)
+  )
+  (make-music 'Music 'void #t)
+)
+
+
+% Set the piece title in a new header block.
+#(define (oly:set_piece_header score piecename)
+  (if (not-null? piecename)
+    (let* ((header (make-module)))
+      (module-define! header 'piece piecename)
+      (ly:score-set-header! score header)
+    )
+    ;#f
+  )
+)
+
+
 % post-filter functions. By default, no filtering is done. However,
 % for the *NoCues* function, the cue notes should be killed
 identity = #(define-music-function (parser location music) (ly:music?) music)
@@ -331,7 +393,7 @@ cuefilter = #(define-music-function (parser location music) (ly:music?)
 )
 
 % The helper function to build a score.
-#(define (createScoreHelper parser location part instr func)
+#(define (oly:createScoreHelper parser location part instr func)
   (let* (
          (staves    (oly:make_parallel_staves parser part "topLevel" instr))
          (music     (if (not-null? staves) 
@@ -343,9 +405,6 @@ cuefilter = #(define-music-function (parser location music) (ly:music?)
          (piecenametacet (namedPieceInstrObject part (car instr) "PieceNameTacet"))
          (header    '())
          )
-    ; Set the piecename in the header and apply it to the score
-    ;(display-lily-music music parser)
-    ;(display-scheme-music music)
     (if (null? music)
       ; No staves, print tacet
       (begin 
@@ -355,13 +414,12 @@ cuefilter = #(define-music-function (parser location music) (ly:music?)
           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") part instr)
         )
       )
-      ; we have staves, apply the piecename to the score
+      ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
       (begin
-        (set! header (make-module))
-        (if (not-null? piecename)
-          (module-define! header 'piece piecename) )
         (set! score (scorify-music music parser))
-        (ly:score-set-header! score header)
+        (oly:set_piece_header score piecename)
+        (oly:apply_score_midi score)
+        (oly:apply_score_layout score)
         ; Schedule the score for typesetting
         (collect-scores-for-book parser score)
       )
@@ -370,11 +428,12 @@ cuefilter = #(define-music-function (parser location music) (ly:music?)
   ; This is a void function, the score has been schedulled for typesetting already
   (make-music 'Music 'void #t)
 )
+
 createScore = #(define-music-function (parser location piece instr) (string? list?)
-  (createScoreHelper parser location piece instr identity)
+  (oly:createScoreHelper parser location piece instr identity)
 )
 createNoCuesScore = #(define-music-function (parser location piece instr) (string? list?)
-  (createScoreHelper parser location piece instr cuefilter)
+  (oly:createScoreHelper parser location piece instr cuefilter)
 )