add tests, rearrange to address review comments (bug 869553)