partially overhaul code