Big overhaul in code.