Add console mode and cleanup code