Tidying up code, support image update and deletion