Code cleanup and formatting as well as minor improvements, in particular removal of unnecessary code.