Slightly improve the performance and remove some unused variables