Lots of changes and clean up in code and structure