refactored and optimized Image.js and Type.js