fixing print out of order problem