massive reorganization and code clean up