optimization of many parts of the code