#4: Code re-organization and cleanup