sort of working but returns it in inverse order