slight refactor, fix error in output