Gallery code refactoring #2. Some code clearing.