refactoring encoding of let rec to share with plain let