This'll need to get synced with the latest changes in the tj-v0.9.9 branch