Merged with Bing Xuan code