restored rewritten code to match master and fixed added or missing line breaks to make the dff easier to read