Cleanup and code re-org + minor fixes