corrected typo that caused seg-fault. Seems to give the right output now