need be rewrited
working to jpg images, need improvements