working version for equal data sizes