Make get_encoded_id() more robust