bug fix and output cleanup