remove rogue $type and add missing #end