Drop priviledges after bind
Fix a few bugs, deduplicate code