cleanup, improved a couple of things, added option to choose output