fixed marking and refinement algorithms, seems to be fine now!