Simplified the code.py considerably and add some comments