fix some bugs, how did this work in the first place?