figure out and fix some bugs