Should probably move detach after stop.  If stop fails you probably don't want to detach.