add tests; remove some unnecessary creation of tmp files in favor of piping