Optimize a little and add some comments