Refactor to separate unit & functional tests