correct version for johnsons algo