Cleaned up a lot of code, factoring responsibilities into simpler classes.