Huge code cleanup and code translation. Must be in good shape now.