slight modification and add comments