I added the requested changes nearly verbatim, some whitespace changes, sorry