Gallery code refactoring. Some code clearing.