First-pass completed code, to be reviewed