very fin atttempt of optimization (commited by indra-uolles from Dmitry PC)