Functional, but need some cleanup, removing double code.