avoiding string duplication in terminal matching