some refactorings, now supporting normal images too