Fix some bugs, improve module tracking