Refactor without foreach
Fix inditifier encode bug, and decode length