added minor optimization when appending images and in toggle button