Fix implicit leaks of imports throughout libraries

Also touch up use of 'pub' and move some tests around so the tested functions
don't have to be 'pub'