split up deftwigfn so bulk of logic is inside a separate function
update function tests
remove unused require