Minor cleanup; add tests