some optimization and data manipulation