Add more functional tests. Make test run well. Fix some warnings.