Modified code to be easier to debug.