Fix various issues with threading and flow

Signed-off-by: Jai Govindani <jai@zodio.com>