fixxed sorting loops