chris- fixed logic errors, and finished code.