modify code according to houndci's report