Security fixes + smaller improvement for final version