What if GeoTiff.getMetadata match returned None? In your refactoring, since you removed "readFirstRecord = true", nextKeyValue will return true instead of false as it does now.