some optimization and comments