Made some refactoring in ImageDatabase