example 4-2: refactor out gravity