making nscd work

I have fixed one bug, which prevented nscd from being started.
The second commit is some small refactoring.