Fix some bugs in output