Rearrange code to avoid nested class definitions.