Fixed some code that caused run time error.