fixed segfault when n=1 (thanks merbs)