Reorganize code (again) and add failing tests