Encoding added and minor bug fixes.