refactored the foreground background stuff a bit