more work making the code similar to external sorted list