Add command line argument parsing and --foreground parameter