Fix for code.py and some slight refactoring.