Fixed unoptimal fragment of code