Fix handling of metacharacters

Metastate was not being handled correctly, so characters were coming out as their base version (see appium/appium#3631). Also add some logging.