fix a whole bunch of bugs, encrypting seems to work again