Refactor Ampton's update logic.

This is an experimental commit. I'm trying to reduce the number of
if-chains based on the state by refactoring common update code into the
function called by state. This is at the expense of code duplication. It
also includes some functions with side effects that I'm not comfortable
with but am not sure how to fix at the moment.