Code used for thesis