Fix runtime error bugs