refactor; add fns and spec