Coverity fixes 20131016

Several issues remain: #179, #180, #182 

This could be merged without them.