Fixed some bugs, flattened a few structures.