Corrected bugs in setImage function