Trying to fix the missing end bug.  Code is not quite right at the moment - need to log to see exactly what is going on.