Added cafile option
Lots of bugfixes and improvements