Some attempts to improve the performance

* It was not sufficient, maybe using arrays is a better approach.