Code significantly restructured.