cleanup

this is a general refactor, and doesn't change behaviour