Updated according to simonw's comments