Added more comments, simplified several codes.