added repair-mode, some bugs fixed