diff --git a/event_display.py b/event_display.py
index 16ead721833f03086606589a4f2b2c480e2af9aa..e270fa14e9b833867e4cf219dbed81422f3f4e6a 100644
--- a/event_display.py
+++ b/event_display.py
@@ -1,54 +1,72 @@
 #!/usr/bin/python
 
-# parse ical calendar and insert values into html template
-
-import requests
-import arrow
-from ics import Calendar
-from jinja2 import Environment, FileSystemLoader
-import os
-
-
-url = 'https://portal.idiv.de/ssf/ical/basic.ics?bi=393&ui=1026&pd=171497477d81eb659bd832ffe26c8bfe39d65fc3&v=1'
-tz = 'Europe/Berlin'
-now = arrow.now(tz)
-period = (now.floor('day'), now.replace(weeks=+4))
-
-
-c = Calendar(requests.get(url).text)
-html_list = []
-for e in c.events:
-    if e.end > period[0] and e.begin < period[1]:
-    # only display events which have not ended yet
-    # and start earlier than defined above
-        duration = e.end - e.begin
-        # short, full day and multi day events display datetime differently
-        if duration.days < 1:
-            event_date = (e.begin.format('DD.MM.YYYY, HH:mm')
-                          + ' &ndash; '
-                          + e.end.format('HH:mm'))
-        elif duration.days == 1:
-            event_date =  e.begin.format('DD.MM.YYYY') + ', all day'
-        elif duration.days > 1:
-            # in ics file the end date is the day after end date at 00:00:00
-            corrected_end_date = e.end.replace(days = - 1)
-            event_date = (e.begin.format('DD.MM.YYYY')
-                          + ' &ndash; '
-                          + corrected_end_date.format('DD.MM.YYYY'))
-        else:
-            event_date = ''
-        # create list of dictionaries for jinja2 template
-        event = dict(date = event_date, name = e.name, location = e.location)
-        html_list.append(event)
-
-# Capture our current directory
-this_dir = os.path.dirname(os.path.abspath(__file__))
-
-# Create the jinja2 environment.
-# Notice the use of trim_blocks, which greatly helps control whitespace.
-j2_env = Environment(loader=FileSystemLoader(this_dir),
-                     trim_blocks=True)
-output = j2_env.get_template('template.html').render(html_list = html_list)
-out_file = open(this_dir + "/website/events.html", "w")
-out_file.write(output.encode("utf-8"))
-out_file.close()
+def main(url, timezone, future_weeks, filename):
+    """parse ical calendar and insert values into html template.
+    """
+    html_list = ics2list(url, timezone, future_weeks)
+    calendarlist2jinja(html_list, filename)
+
+def ics2list(url, timezone, future_weeks):
+    """parse ical calendar into a list
+    """
+    import requests
+    import arrow
+    from ics import Calendar
+
+    now = arrow.now(timezone)
+    period = (now.floor('day'), now.replace(weeks=+future_weeks))
+
+    calendar = Calendar(requests.get(url).text)
+    html_list = []
+    for event in calendar.events:
+        if event.end > period[0] and event.begin < period[1]:
+        # only display events which have not ended yet
+        # and start earlier than defined above
+            duration = event.end - event.begin
+            # short, full day and multi day events display datetime differently
+            if duration.days < 1:
+                event_date = (event.begin.format('DD.MM.YYYY, HH:mm')
+                              + ' &ndash; '
+                              + event.end.format('HH:mm'))
+            elif duration.days == 1:
+                event_date = event.begin.format('DD.MM.YYYY') + ', all day'
+            elif duration.days > 1:
+                # in ics file the end date is the day after end date at 00:00:00
+                corrected_end_date = event.end.replace(days=- 1)
+                event_date = (event.begin.format('DD.MM.YYYY')
+                              + ' &ndash; '
+                              + corrected_end_date.format('DD.MM.YYYY'))
+            else:
+                event_date = ''
+            # create list of dictionaries for jinja2 template
+            event = dict(date=event_date,
+                         name=event.name,
+                         location=event.location)
+            html_list.append(event)
+    return html_list
+
+def calendarlist2jinja(html_list, filename):
+    """write list of events to jinja html template
+    """
+
+    import os
+    from jinja2 import Environment, FileSystemLoader
+
+    # Capture our current directory
+    this_dir = os.path.dirname(os.path.abspath(__file__))
+
+    # Create the jinja2 environment.
+    # Notice the use of trim_blocks, which greatly helps control whitespace.
+    j2_env = Environment(loader=FileSystemLoader(this_dir),
+                         trim_blocks=True)
+    output = j2_env.get_template('template.html').render(html_list=html_list)
+    out_file = open(this_dir + filename, "w")
+    out_file.write(output.encode("utf-8"))
+    out_file.close()
+
+
+if __name__ == '__main__':
+    main(url='https://portal.idiv.de/ssf/ical/basic.ics?bi=393&ui=1026&pd=171497477d81eb659bd832ffe26c8bfe39d65fc3&v=1',
+         timezone='Europe/Berlin',
+         future_weeks=4,
+         filename="/website/events.html")