Fixed some runtime bugs