Soved issue #280. Adopts the code of luuthanhtuan.