fixed error messages
check stream and encoding before use