Massive cleanup of the entire codebase. Notable changes include: