A general approach to list decoding