Fixed some bugs, including some in BNSharp