Added support for running in foreground