Updated with Handong's code.