Fixed a very sneaky bug causing segmentation fault.