changing loop for background and foreground

changing loop for background and foreground