First working version passing functional tests