Code cleanup and file reorganization