added bulk of code done yesterday