A few improvements to code clarity + performance)