added some optimization