shit, it finally works (except for a minor segmentation error)