added value check for i and j.
simpler output