Fixed some bugs and output issues