simplified some code.  still ready to be reviewed