Added end pointer to decode_internal