write in end() as slight optimisation