Fix: invalid reading in gets function