Moved code from notebook to python file