added SOME error checking in input, and kind of fixed bug in output.