more work on image middleware