Moved task creation on the stack into its own function