Feature/security extraction

Tidying things up and fixing things that only became clear when running in a cluster yesterday.