Refactor functional testing