Reformatted Handong's function.