Minor cleanup; add some utility functions