Major Restructure: redo nested dictionary code with better functions