established file layout and fixed some serious nesting bugs