Fixed a bug resulting program to crash