fix algorithm for background images rendering