refactored to provide a decoder factory