Add code from discussion section