Fix runtime bugs