Restructured. Writing some tests to check it works well.