changed script to accomodate Gallery UI change