diff --git a/python/dune/perftool/compile.py b/python/dune/perftool/compile.py
index 7c0b169a108c2b1063d2c0bbc2fcc2ebea90c899..d158a0228bc2a880509a36b001886e7cacdad136 100644
--- a/python/dune/perftool/compile.py
+++ b/python/dune/perftool/compile.py
@@ -4,24 +4,46 @@ The methods to run the parts of the form compiler
 Should also contain the entrypoint methods.
 """
 from __future__ import absolute_import
-from os.path import splitext
+from os.path import basename, splitext
 
-# Disable loopy caching before we do anything else!
 import loopy
+
+from ufl.algorithms import compute_form_data, read_ufl_file
+from ufl.algorithms.formfiles import interpret_ufl_namespace
+
+from dune.perftool.generation import delete_cache_items, global_context
+from dune.perftool.interactive import start_interactive_session
+from dune.perftool.options import get_option
+from dune.perftool.pdelab.driver import generate_driver
+from dune.perftool.pdelab.localoperator import (generate_localoperator_basefile,
+                                                generate_localoperator_file,
+                                                generate_localoperator_kernels,
+                                                name_localoperator_file)
+from dune.perftool.ufl.preprocess import preprocess_form
+
+
+# Disable loopy caching before we do anything else!
 loopy.CACHING_ENABLED = False
 
 
 def read_ufl(uflfile):
-    from ufl.algorithms.formfiles import read_ufl_file, interpret_ufl_namespace
-    from ufl.algorithms import compute_form_data
+    """Read uflfile file, extract and preprocess forms
 
+    Arguments:
+    ----------
+    uflfile: Path to ufl file.
+
+    Returns:
+    --------
+    formdatas: List of formdatas found in uflfile.
+    forms: List of forms found in uflfile.
+    """
     # Read the given ufl file and execute it
     uflcode = read_ufl_file(uflfile)
     namespace = globals()
     try:
         exec("from dune.perftool.ufl.execution import *\n" + uflcode, namespace)
     except:
-        import os
         basename = os.path.splitext(os.path.basename(uflfile))[0]
         basename = "{}_debug".format(basename)
         pyname = "{}.py".format(basename)
@@ -31,12 +53,11 @@ def read_ufl(uflfile):
             f.write(pycode)
         raise SyntaxError("Not a valid ufl file, dumped a debug script: {}".format(pyname))
 
-    # Extract the form from the given data
+    # Extract and preprocess the forms
     data = interpret_ufl_namespace(namespace)
     formdatas = []
     forms = data.forms
     for index, form in enumerate(forms):
-        from dune.perftool.ufl.preprocess import preprocess_form
         formdatas.append(preprocess_form(form))
         forms[index] = formdatas[index].preprocessed_form
 
@@ -48,40 +69,32 @@ def read_ufl(uflfile):
 
 # This function is the entrypoint of the ufl2pdelab executable
 def compile_form():
-    from dune.perftool.options import get_option
     formdatas, data = read_ufl(get_option("uflfile"))
 
-    from dune.perftool.generation import global_context
     with global_context(data=data, formdatas=formdatas):
         # Generate driver file
         if get_option("driver_file"):
-            from dune.perftool.pdelab.driver import generate_driver
             generate_driver(formdatas, data)
 
     # In case of multiple forms: Genarate one file that includes all localoperator files
     if len(formdatas) > 1:
-        from dune.perftool.pdelab.localoperator import generate_localoperator_basefile
         generate_localoperator_basefile(formdatas, data)
 
     # Generate local operator files
     for formdata in formdatas:
         with global_context(data=data, formdata=formdata):
             # Make sure cache is empty
-            from dune.perftool.generation import delete_cache_items
             delete_cache_items()
 
+            # Create localoperator kernels
             if get_option("operator_file"):
-                from dune.perftool.pdelab.localoperator import generate_localoperator_kernels
                 kernels = generate_localoperator_kernels(formdata, data)
 
             # TODO insert sophisticated analysis/feedback loops here
             if get_option("interactive"):
-                from dune.perftool.interactive import start_interactive_session
                 start_interactive_session(kernels)
 
+            # Create c++ file from kernels
             if get_option("operator_file"):
-                from dune.perftool.pdelab.localoperator import name_localoperator_file
                 filename = name_localoperator_file(formdata, data)
-
-                from dune.perftool.pdelab.localoperator import generate_localoperator_file
                 generate_localoperator_file(formdata, kernels, filename)