fix a couple of bugs lowering performance