cleaned older version
full rewrite
added comment for sizeX and sizeY