Found bug. Now gives correct output.