code refactoring,fix bug with images