remove a bunch of unsafety, and hopefully improved performance