Optimization of working with lists