Refactor and fix image loader.