Refactor, unit tests half done