Some proposed code and additional pseudo-code