Some changes, most of these were made long ago but not commited, so I cannot vouch for the correctness of the code.