Some cleanup. Add more commenting. Restructure interactive mode.