Updated according to Alexander Zaytsev's suggestion