File reorganization and fixing build problems