Fixed bug causing seg fault