cleaned input/output up a bit including some more error checking on input