Fixed bug in plan repairing, added unit test