fix problem when beg starts at zero
fix problem when beg starts at zero