new working sort with actual memory