Functional, but in need of rewrite