fix some bugs, looks to be working