fix some bugs, does run now without crashing.