Further porting. Began with rewriting window generation.