Manually merged in changes from scarletrain