Moved launch code to a separate function