Fixed up the logic for reading values