implements privilege dropping and improves logging