working fine for large dataset