fix bug and tidy output