Completed restructure function, but need to defensively test code for bugs