Refactor structure and functional tests