Restructuring into sane code.