Fix some more bugs (coverity you're a life saver)