Jin - 2013-12-26

Did not use your patch directly, but understood the problem and mostly did the same in C++, thanks for figuring this out.