added code to remove extra lines in output