Correctness asserted

need further improvement of memory cleaning up