restructured + added some important code