bug fixes

The only thing I'm not really sure about here is 8e1e41547d8a9a26513d31d5ddaef87641083f4f

I think the others are self explanatory