Fix various run time errors
merge