better handling of pidfile
a bit of renaming and cleanup