Refactor functional tests