Bug fixes and structure clean up