trying to fix carpet algorithm