Moved image width and height to vars and directly modifying pixels array instead of using set pixel