Minor perfomance optimization, possible some bugs are introduced -> need to cover code with unit tests