Fixed a few logic issues and output issues