I think there is a bug here. If res is nil, it will fall into this elsif and throw a nil exception when trying to access code.