updated for multiple encodings