fix sorting and make integration test robust by sorting