Modified much of the code to use bytearrays internally. Some omissions remain.