Clean up the debug and add a totalling mechanism for the diff functions