improved code of chunk_equals