refactor testing into unit and functional tests