More cleanup and some refactoring in ImageManager.php