Code used in Master's thesis 2013