updated with comments and diagnostic stopwatch