updated to handle running in background thread which doesn't have Alloy present.