work for #50.
split the update method into a couple different methods to improve code readability.