Added translation of Ngiam's code.