fix bug in script for bg pattern