Security improvement: created socket earlier in the code so we can drop root sooner