Main code and tests.