fixed a segfault, improved normal vector calculation (still wrong though...)