Refactoring c decoder to use less duplicated code sequences