Fixed a bug with invisible images

Fixed a bug with invisible images + streamlined and beautified code
Removed script size, improved performance