fix null dereferences

reported by coverity's free scanner
change functions around to have failure as default mode