Code used for my phd thesis