extended to replace keys found in messages