Improved img function v2