fix some bugs and improve image upload