cleaned up terminal code