Use logger for console output. Add history argument. Code cleanup.