added optional running in foreground, defaults to background