better handling of failure to join
wrapping in self executing function