Code organization and cleanup