Refactor tests so they don't leak