Moved img variable to the top