added more logging to this example
made version 3 far more elegant